package com.neolix.watch.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.neolix.watch.NeolixApplication;
import com.neolix.watch.R;
import com.neolix.watch.domain.RemindEventViewModel;
import com.neolix.watch.util.FontTypefaceUtil;
import com.neolix.watch.util.StringUtil;

import static com.neolix.watch.NeolixApplication.getInstance;
import static com.neolix.watch.util.FontTypefaceUtil.setTypefaceOfHelvetica;
import static com.neolix.watch.util.StringUtil.isBlank;

public class RemindItemView extends LinearLayout {

    private TextView deviceAddressTextView;
    private TextView deviceNameTextView;
    private TextView contentTextView;
    private TextView remindDateTextView;
    private TextView remindTimeTextView;
    private TextView amPmTextView;

    public RemindItemView(Context context) {
        super(context);
        initUi();
    }

    public RemindItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initUi();
    }

    public RemindItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initUi();
    }

    protected void initUi() {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View container = inflater.inflate(R.layout.view_remind_item, this, true);

        contentTextView = (TextView) container.findViewById(R.id.remind_content);
        remindDateTextView = (TextView) container.findViewById(R.id.remind_date);
        remindTimeTextView = (TextView) container.findViewById(R.id.remind_time);
        amPmTextView = (TextView) container.findViewById(R.id.AM_PM_text_view);

        setTypefaceOfHelvetica(remindTimeTextView);
        setTypefaceOfHelvetica(amPmTextView);
    }


    public void setModel(RemindEventViewModel model) {
        if (isBlank(model.getContent())) {
            contentTextView.setText(getInstance().getString(R.string.no_remind_event));
            remindDateTextView.setVisibility(GONE);
            remindTimeTextView.setVisibility(GONE);
            amPmTextView.setVisibility(GONE);
            return;
        }

        remindDateTextView.setVisibility(VISIBLE);
        remindTimeTextView.setVisibility(VISIBLE);
        amPmTextView.setVisibility(VISIBLE);
        contentTextView.setText(model.getContent());
        remindDateTextView.setText(model.getDate());
        remindTimeTextView.setText(model.getTime());
        amPmTextView.setText(model.getAmPm());
    }
}
